package com.appbee.yahoo.query.client.ui;

import com.appbee.yahoo.query.client.model.Album;
import com.appbee.yahoo.query.client.model.Track;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.Column;

public class TrackCellTable extends CellTable<Track>
{

	public TrackCellTable(int pageSize,
			com.google.gwt.user.cellview.client.CellTable.Resources resources)
	{
		super(pageSize, resources);
		addColumns();
	}
	
	private void addColumns()
	{
		addColumn(new TextCol()
		{
			
			@Override
			public String getValue(Track object)
			{
				return object.getTitle();
			}
		},"Titill");
		addColumn(new TextCol()
		{
			
			@Override
			public String getValue(Track object)
			{
				return object.getArtist()==null?"":object.getArtist().getName();
			}
		},"Flytjandi");
		addColumn(new TextCol()
		{
			
			@Override
			public String getValue(Track object)
			{
				Album album = object.getAlbum();
				if(album!=null && album.getRelease()!=null)
				{
					return album.getRelease().getTitle();
				}
				return "";
			}
		},"Plata");
		addColumn(new TextCol()
		{
			
			@Override
			public String getValue(Track object)
			{
				return object.getCategory()==null?"":object.getCategory().getName();
			}
		},"Flokkur");
	}
	
	
	private abstract class TextCol extends Column<Track, String>
	{
		public TextCol()
		{
			super(new TextCell());
		}
		
	}
	
}
